/*
 * FileName: simpleFactory.cc
 * Author: 李波(Edwin Lee)
 * Date: 2024-07-16 11:21:14
 * Version: 1.0
 * Description: 简单工厂模式定义：定义了一个创建对象的类，由这个类来封装实例化对象的行为。
 */
#include <iostream>
using namespace std;

enum CarType{BMW,AUDI};
class Car 
{
public:
	Car(string name):name_(name){}
	virtual void show() = 0;
protected:
	string name_;
};

class Bmw:public Car
{
public:
	Bmw(string name):Car(name){}
	void show(){cout<<"获取一辆宝马汽车"<<endl;}
};

class Audi:public Car
{
public:
	Audi(string name):Car(name){}
	void show(){cout<<"获取一辆奥迪汽车"<<endl;}
};

class SimpleFactory
{
public:
	Car* createCar(CarType ct)
	{
		switch(ct)
		{
			case BMW:
				return new Bmw("X1");
			case AUDI:
				return new Audi("A6");
			default:
				cerr << "传入工厂的参数不正确:" << ct << endl;
		}
		return nullptr;
	}

};

int main()
{
	SimpleFactory factory;
	factory.createCar(BMW)->show();
	factory.createCar(AUDI)->show();
	
	return 0;
}
